function obj2str(date){
    date.t=new Date().getTime();
    var res=[];
    for(var key in date){
        res.push(encodeURIComponent(key)+"="+encodeURIComponent(date[key]));        
    }
    return res.join("&");
}
function ajax(option) {
    //将对象转换为字符串
    var str=obj2str(option.date);
    var xmlhttp,timeout;
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //转换成小写
    if(option.type.toLowerCase==="get"){
        xmlhttp.open(option.type, option.url+"?t"+option.str, true);
        xmlhttp.send();
    }else{
        xmlhttp.open(option.type,option.url,true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send(option.str);
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            clearInterval(Timer);
            if (xmlhttp.status >= 200 && xmlhttp.status < 300 || xmlhttp.status === 304) {
                option.success(xmlhttp);
            } else {
                option.error(xmlhttp);
            }
        }
    }
    if(option.timeout){
        Timer=setInterval(function(){
            console.log("请求超时，中断请求");
            xmlhttp.abort();
            clearInterval(Timer);
        },option.timeout);
    }
}